/******************************************************************************
 * Copyright 2022 The Airos Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#pragma once

#include "track_util.h"

namespace airos {
namespace perception {
namespace algorithm {
namespace track2d {

class KalmanFilter {
 public:
  static const double chi2inv95[10];
  KalmanFilter();
  KAL_DATA initiate(const DETECTBOX& measurement);
  void predict(KAL_MEAN& mean, KAL_COVA& covariance);
  KAL_HDATA project(const KAL_MEAN& mean, const KAL_COVA& covariance);
  KAL_DATA update(const KAL_MEAN& mean, const KAL_COVA& covariance,
                  const DETECTBOX& measurement);

 private:
  Eigen::Matrix<float, 8, 8, Eigen::RowMajor> _motion_mat;
  Eigen::Matrix<float, 4, 8, Eigen::RowMajor> _update_mat;
  float _std_weight_position;
  float _std_weight_velocity;
};

}  // namespace track2d
}  // namespace algorithm
}  // namespace perception
}  // namespace airos
